package com.relsell.view;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

import android.os.AsyncTask;
import android.util.Log;
import com.relsell.utility.AppVars;
import com.relsell.utility.UtilitySingleTon;

public class Register extends AsyncTask<Void, Void, Boolean> {

		String responseString;

		@Override
		protected void onPreExecute() {
			super.onPreExecute();

		}

		@Override
		protected Boolean doInBackground(Void... params) {
			try {

				HttpClient http = new DefaultHttpClient();
				String server = AppVars.getServer();
				HttpPost post = new HttpPost("http://" + server
						+ "/gcminteraction/view/start.php?controlVar=2");
				List<NameValuePair> data = new ArrayList<NameValuePair>();
				Log.w("Product", "1");
				Log.w("Product", Login.logedinuserid);
				data.add(new BasicNameValuePair("registrationid",UtilitySingleTon.getInstance().getgCMRegId()));
				data.add(new BasicNameValuePair("loggedinuserid", AppVars.sloggedInUserId));
				post.setEntity(new UrlEncodedFormEntity(data));

				HttpResponse response = http.execute(post);

				responseString = new BasicResponseHandler()
						.handleResponse(response); // Basic handler
				if (AppVars.isLogEnabled) {
					Log.v(AppVars.LOG_TAG, "Response String =" + responseString);
				}
				// result = obj.getString("loggedIn");

				return true;
			} catch (ClientProtocolException e) {

			} catch (IOException e) {

			}
			return false;
		}

		@Override
		protected void onPostExecute(Boolean success) {
		}
	}
